<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item v-if="!$store.state.user.MerchantId">
          <el-select v-model="dataForm.merchantId" placeholder="商户" clearable>
            <el-option
              :value="item.id"
              v-for="item in shs"
              :key="item.id"
              :label="item.name"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" placeholder="订单状态" clearable>
            <el-option
              :value="item.value"
              v-for="item in status"
              :key="item.value"
              :label="item.label"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.orderType"
            placeholder="订单类型"
            clearable
          >
            <el-option label="包船" :value="2"> </el-option>
            <el-option label="拼船" :value="3"> </el-option>
            <el-option label="特价船" :value="1"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.orderCode"
            placeholder="订单编号"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            v-if="$hasPermission('fishering:order:export')"
            @click="exportHandle()"
            >{{ $t("export") }}</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="danger"
            v-if="$hasPermission('fishering:order:delete')"
            @click="deleteHandle(id)"
            >{{ $t("deleteBatch") }}</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="orderCode"
          label="订单编号"
          :show-overflow-tooltip="true"
          header-align="center"
          min-width="170"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="orderType"
          label="订单类型"
          header-align="center"
          min-width="120"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.orderType | delStatus }}
          </template>
        </el-table-column>
        <el-table-column
          prop="playDate"
          label="游玩日期"
          min-width="150"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="playTime"
          label="游玩时间"
          min-width="150"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="num"
          label="数量"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="linkName"
          label="联系人"
          :show-overflow-tooltip="true"
          header-align="center"
          min-width="150"
          align="center"
        ></el-table-column>
        <!-- <el-table-column
          prop="linkPhone"
          label="联系电话"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column> -->
        <el-table-column
          label="联系电话"
          header-align="center"
          min-width="120"
          align="center">
          <template slot-scope="scope">
            <i @click="showReal=scope.$index">{{ scope.$index===showReal ? scope.row.realPhone : scope.row.linkPhone }}</i>
          </template>
        </el-table-column>
        <el-table-column
          prop="realPrice"
          label="实付价"
          min-width="150"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="orderTime"
          label="下单时间"
          header-align="center"
          min-width="180"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          min-width="150"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.status | orderStatus }}
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              v-if="
                scope.row.status == 2 &&
                scope.row.orderType == 3 &&
                $hasPermission('scenic:goods:noSpell')
              "
              @click="mianpin(scope.row.id)"
              >免拼</el-button
            >
            <el-button
              type="text"
              v-if="$hasPermission('fishering:order:info')"
              size="small"
              @click="lookDetail(scope.row.orderCode)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
      <!-- 详情 -->
      <detail ref="lookDetail" v-if="lookDetailVisible"> </detail>
    </div>
  </el-card>
</template>
    
    <script>
var that;
import mixinViewModule from "@/mixins/view-module";
import detail from "./orderDetail";
export default {
  mixins: [mixinViewModule],
  components: {
    detail,
  },
  filters: {
    delStatus(val) {
      if (val) {
        let d = that.orderType.filter((item) => item.value == val);
        if (d.length != 0) {
          return d[0].label;
        }
      }
    },
    orderStatus(val) {
      if (val||val===0) {
        let d = that.status.filter((item) => item.value == val);
        if (d.length != 0) {
          return d[0].label;
        }
      }
    },
  },
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/api/fishering/personCenterPage",
        getDataListIsPage: true,
        createdIsNeed: false,
        exportURL: "/scenic/order/export",
      },
      orderType: [
        {
          label: "特价",
          value: 1,
        },
        {
          label: "包船",
          value: 2,
        },
        {
          label: "拼船",
          value: 3,
        },
      ],
      payType: [
        {
          label: "微信",
          value: 1,
        },
        {
          label: "支付宝",
          value: 2,
        },
      ],
      status: [
        {
          label: "待支付",
          value: 0,
        },
        {
          label: "待使用",
          value: 1,
        },
        {
          label: "拼船中",
          value: 2,
        },
        {
          label: "已使用",
          value: 3,
        },
        {
          label: "退款中",
          value: 4,
        },
        {
          label: "已退款",
          value: 5,
        },
        {
          label: "已取消",
          value: 6,
        },
        {
          label: "已完成",
          value: 7,
        },
        {
          label: "拼团失败",
          value: 8,
        },
      ],
      shs: [],
      dataForm: {
        // name: '',
        orderType: "",
        orderCode: "",
        status: "",
        merchantId:
          this.$store.state.user.MerchantId ||
          localStorage.getItem("MerchantId"),
        // status: '',
        // activity: '',
        // islandId: '',
        // linkName: '',
        // phone: '',
      },
      showReal:''
    };
  },
  created() {
    that = this;
    if (this.$store.state.user.MerchantId) {
      this.getDataList();
    } else {
      this.getSh();
    }
  },
  methods: {
    getSh() {
      this.$http
        .get("/scenic/merchant/info/page", {
          params: {
            page: 1,
            limit: 50,
            merchantCategory: 10,
            status: 1,
          },
        })
        .then((res) => {
          if (res.data.code == 0) {
            this.shs = res.data.data.list;
            this.dataForm.merchantId = this.shs[0].id;
            this.getDataList();
          }
        });
    },
    mianpin(id) {
      this.$confirm("确定该操作？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http.get("/scenic/order/noSpell/" + id).then((res) => {
            if (res.data.code == 0) {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.getDataList();
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>
    